package cn.cvs.servlet;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.service.EdocEntryService;
import cn.cvs.service.impl.EdocEntryServiceImpl;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @auth 吴阳基
 * @date 2024/01/05 14:18
 */
@WebServlet(urlPatterns = "/delete")
public class DeleteServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        EdocEntryService ardService = new EdocEntryServiceImpl();
        SqlSession sqlSession=null;
        int id=0;
        id= Integer.parseInt(request.getParameter("id"));
        try {
            sqlSession = MyBatisUtil.createSqlSession();
            id = sqlSession.getMapper(SysUserMapper.class).delete(id);
            sqlSession.commit();

        } catch (Exception e) {
            e.printStackTrace();
            sqlSession.rollback();
            id = 0;
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
        int delete = ardService.delete(id);
        PrintWriter out=response.getWriter();
        out.print(delete);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
